# 处理多张图片
import numpy as np
import cv2
import os.path
import glob
import time
from PIL import Image
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

def convertjpg(jpgfile,outdir,width=640,height=480):
    img=Image.open(jpgfile)
    if img.size[0] == 1920 and img.size[1] == 1080:    
    #new_img=img.resize((width,height),Image.BILINEAR)
        box = (240, 0, 1680, 1080)
        roiImg = img.crop(box)

        new_img=roiImg.resize((width,height),Image.BICUBIC)   
        new_img.save(os.path.join(outdir,os.path.basename(jpgfile)), quality=95, subsampling=0)

print("开始处理：")
start = time.time()

for jpgfile in glob.glob("/home/longpj/bianli24_119/Documents/24bianli_data_image_ori_deal_due_20201202/shekou/image_20201126_3/*.jpg"):
    convertjpg(jpgfile,"./image_20201126_3")
    
end = time.time()
print("处理完成，resize照片耗时: %s分" % ((end - start) / 60))
